#pragma once 

#include "utf8.h"

#include <string>
#include <sstream>


namespace SmsAlg
{
    /**
    * Class converts numeric and string values to UTF-8 string 
    */
    class Utf8String
    {
    public:
        Utf8String(){}

        Utf8String(const Utf8String & utfstr)
        {
            stream.str(utfstr.stream.str());
        }

        Utf8String(const std::wstring & wstr)
        {
            *this << wstr;
        }

        Utf8String(const std::string & str)
        {
            *this << str;
        }
        
        Utf8String & operator << (const std::wstring & val)
        {
            std::string str = xpam::string::unicode_to_utf8(val);
            stream << str;
            return *this;
        }

        Utf8String & operator << (const wchar_t * val)
        {
            std::wstring wstr(val);
            *this << wstr;
            return *this;
        }

        template <class T>
        Utf8String & operator << (const T & val)
        {
            stream << val;
            return *this;
        }

        operator std::string () 
        { 
            stream.flush();
            return stream.str(); 
        }

        operator const char * () 
        { 
            stream.flush();
            strv = stream.str();
            return strv.c_str(); 
        }

        std::string str()
        {
            return stream.str();
        }

        void clear()
        {
            stream.str("");
        }


    private:
        std::ostringstream stream;
        std::string strv;
    };
} //namespace